<template>
  <el-container class="app-container">
    <el-collapse @change="handleCollapseChange" v-model="collapseActiveName">
      <el-collapse-item :title="collapseTitle" name="1">
        <el-tabs type="border-card">
          <el-form :model="pageInfo" ref="form" label-width="120px" size="medium">
            <el-row>
              <el-col :span="4" :offset="0">
                <el-form-item prop="groupId" label="报修对象:">
                  <el-select v-model="pageInfo.groupId" placeholder="请选择">
                    <el-option
                      v-for="item in statusOptions"
                      :key="item.value"
                      :label="item.label"
                      :value="item.value">
                    </el-option>
                  </el-select>
                </el-form-item>
              </el-col>
              <el-col :span="7" :offset="1">
                <el-form-item prop="dateRange" label="优惠券有效期：">
                  <el-date-picker clearable v-model="dateRange" type="datetimerange" align="right"
                                  value-format="yyyy-MM-dd HH:mm:ss" unlink-panels range-separator="至"
                                  start-placeholder="开始日期"
                                  end-placeholder="结束日期" @change="handleDateRange">
                  </el-date-picker>
                </el-form-item>
              </el-col>
              <el-col :span="3" :offset="0">
                <el-form-item prop="groupId" label="故障类型:">
                  <el-select v-model="pageInfo.groupId" placeholder="请选择">
                    <el-option
                      v-for="item in statusOptions"
                      :key="item.value"
                      :label="item.label"
                      :value="item.value">
                    </el-option>
                  </el-select>
                </el-form-item>
              </el-col>
              <el-col :span="3" :offset="0">
                <el-form-item prop="groupId" label="状态:">
                  <el-select v-model="pageInfo.groupId" placeholder="请选择">
                    <el-option
                      v-for="item in statusOptions"
                      :key="item.value"
                      :label="item.label"
                      :value="item.value">
                    </el-option>
                  </el-select>
                </el-form-item>
              </el-col>

              <el-col :span="3" :offset="1" >
                <el-button type="primary" icon="el-icon-search" @click='getData'>搜索</el-button>
                <!--                  <el-button @click="resetForm">重置</el-button>-->
              </el-col>
            </el-row>
          </el-form>
        </el-tabs>
      </el-collapse-item>
    </el-collapse>
    <el-header class="m-t-20">
      <el-button type="primary" icon="el-icon-plus" @click="addOne">费用类型</el-button>
    </el-header>

    <!--表格-->
    <table-view
      :columns="tableContent"
      :pageList="columnData"
      :templateDiv="{operation:true}"
    >
      <template slot="operation" slot-scope="scope">
        <el-button size="mini" type="" @click="editBtnClick(scope.row ,'view')">报修详情</el-button>
        <el-button size="mini" type="primary" @click="editBtnClick(scope.row ,'handle')">受理</el-button>

      </template>
    </table-view>

    <!--分页-->
    <pagination-view :pagesize="pageInfo.pageSize"
                     :currentPage="pageInfo.pageNumber"
                     :total="total"
                     @size-change="sizeChange"
                     @current-change="pageChange"
    ></pagination-view>

    <el-dialog title="查看" :visible.sync="dialogVisible" width="60%"
               :destroy-on-close="true" :before-close="handleClose">
      <el-row class="view-area">
        <el-col :span='8' offset="1">
          <p>报修ID:{{form.id}}</p>
          <p>报修对象:</p>
          <p>故障类型:</p>
          <p>问题描述:</p>
          <p>附图: <img :src="form.areaPic" alt="" style="width: 100px;vertical-align: top"></p>
          <p>报修人:{{form.areaName}}</p>
          <p>联系电话:{{form.addressName}}-{{form.address}}</p>
          <p>报修时间:{{form.status}}</p>
          <p>备注:{{form.remark}}</p>
          <p>状态:{{form.status?'开启':'停用'}}</p>
        </el-col>
       <!-- <el-col :span='8' offset="3">
          <h4>操作记录</h4>
          <p>创建:</p>
          <p>
            {{form.createLog.length?form.createLog[0].createdTime:''}}({{form.createLog.length?form.createLog[0].operatorName:''}})</p>
          <el-row v-if="form.editLog.length">
            <p>编辑:</p>
            <p v-for="(item,i) in form.editLog" :key="i">{{item.operatorName}}({{item.operatorName}})</p>
            <p>空间备注:{{form.remark}}</p>
          </el-row>
        </el-col>-->
      </el-row>
    </el-dialog>
    <el-footer></el-footer>
  </el-container>
</template>

<script>
  import TableView from '@/components/TableView'
  import ImgUpload from '@/components/ImgUpload'

  import PaginationView from '@/components/PaginationView'
  import * as pageApi from '@/api/dailyService/warrantyBill'

  export default {
    name: 'list',
    components: {
      TableView,
      PaginationView,
      ImgUpload
    },
    data() {
      return {
        dateRange:[],
        statusOptions:[{label:'全部',value:''},{label:'正常',value:'1'},{label:'关闭',value:'0'}],
        dialogVisible:false,
        tableContent:[{
          field: 'productName',
          label: '报修单号'
        }, {
          field: 'productName',
          label: '报修对象'
        }, {
          field: 'productName',
          label: '问题描述'
        },{
          field: 'productName',
          label: '附图'
        },{
          field: 'productName',
          label: '故障类型'
        },{
          field: 'productName',
          label: '报修人'
        },{
          field: 'productName',
          label: '联系电话'
        },{
          field: 'productName',
          label: '报修时间'
        },{
          field: 'productName',
          label: '状态'
        },{
          field: 'productName',
          label: '备注'
        },{
          field: 'operation',
          label: '操作',
          width:200
        }],
        columnData: [{}, {}],
        customWidth: '',
        pageInfo: {
          pageNum: 1,
          pageSize: 20,
          title: ''
        },
        total: 0,
        form: {
          costAmount: '',
          intro: '',
          memo: '',
          title: '',
          addressDetail: '',
          addressName: '',
          saleAmount: '',
          sort: ''
        },
        rules: {
          productName: [
            {required: true, trigger: 'blur', message: '名称不能为空'},
            {min: 1, max: 14, message: '长度不能超过14个汉字'}
          ],
          intro: [
            {required: true, trigger: 'blur', message: '简介不能为空'},
            {min: 1, max: 20, message: '长度不能超过20个汉字'}
          ],
          durationTime: [{required: true, trigger: 'change', message: '请选择套餐时长'}],
          sort: [{required: true, trigger: 'blur', message: '请填写排序'}],
          enable: [{required: true, trigger: 'change', message: '请选择套餐状态'}],
          tag: [{min: 1, max: 4, trigger: 'blur', message: '长度不能超过4个汉字'}],
        }
      }
    },
    watch: {},
    methods: {
      handleDateRange(val) {
        this.pageInfo.startTime = val[0]
        this.pageInfo.endTime = val[1]
      },

      addOne() {
        this.dialogVisible = true
        this.dialogTitle = '添加'
      },

      changeUserStatus: function (id, enable) {
        pageApi.changeEnable(id, enable).then((res) => {
          this.handleMessage(res)
          if (res.code === '200') this.getData()
        })
      },
      onSubmit() {
        let form = this.form
        let dialogType = this.dialogType
        form.duration = form.durationTime + (form.productTypeId == 1 ? '个月' : '天')
        form.enable = Number(form.enable)
        this.$refs['form'].validate((valid) => {
          if (valid) {
            switch (dialogType) {
              case 'add':
                this.dialogTitle = '添加'
                pageApi.create(form).then(res => {
                  this.handleRes(res)
                })
                break
              case 'update':
                this.dialogTitle = '编辑'
                pageApi.update(form).then(res => {
                  this.handleRes(res)
                })
                break
            }
          }
        })
      },
      handleRes(res) {
        this.handleMessage(res)
        if (res.code === '200') {
          this.dialogVisible = false
          this.getData()
        }
      },
      // pageSize变化函数
      sizeChange(val) {
        this.pageInfo.pageSize = val
        this.getData()
      },
      // page变化函数
      pageChange(val) {
        this.pageInfo.pageNumber = val
        this.getData()
      },
      editBtnClick(val, type) {
        switch (type) {
          case 'view':
            pageApi.getById(val.courseProductId).then(res => {
              this.form = Object.assign({}, this.form, res.body)

            })
            this.dialogVisible = true
            break
          case 'handle':

            break
        }
      },
      //拉取列表
      getData() {
        pageApi.getList(this.pageInfo).then(res => {
          this.columnData = res.body.records
          this.total = Number(res.body.total)
          this.pageInfo.pageNumber = Number(res.body.pageNumber) || 1
        })
      },
      handleClose(done) {
        let resetForm = {
          costAmount: '',
          courseProductId: '',
          duration: '',
          durationTime: '',
          enable: true,
          intro: '',
          memo: '',
          productName: '',
          saleAmount: '',
          sort: '',
          tag: ''
        }
        this.form = Object.assign({}, this.form, resetForm)
        done()
      }

    },
    mounted() {

      this.getData()
    }
  }
</script>

<style lang="scss" scoped>

</style>
